NowthisdocumentationisspecifictoMongoDB,whichmeansit's
goingtoworkwithallofthedrivers.Inthiscase,itisgoingtowork
withourNode.jsdriver.Ifwescrolldownfurther,wecanlookatall
oftheupdateoperatorswehaveaccessto.Themostimportant,and
theonewe'regoingtogetstartedwith,isthe$setoperator.Thislets
ussetafield'svalueinsideofourupdate,whichisexactlywhatwe
wanttodo.There'sotheroperators,likeincrement.Thisone,$inc,
letsyouincrementafield'svalue,liketheagefieldinourUsers
collection.Althoughthesearesuperuseful,we'regoingtoget
startedwith$set.Inordertouseoneoftheseoperators,whatwe
needtodoistypeitout,$set,andthensetitequaltoanobject.In
thisobject,thesearethethingsthatwe'reactuallygoingtobe
setting.Forexample,wewanttosetcompletedequaltotrue.Ifwetried
toputcompletedequaltotrueattherootoftheobjectlikethis,itwould
notworkasexpected.Wehavetousetheseupdateoperators,which
meansweneedthis.Nowthatwehaveourupdatesinplaceusing
thesetupdateoperator,wecangoaheadandprovideourthirdand
finalargument.Ifyouheadovertothedocumentationfor
findOneAndUpdate,wecantakealookattheoptionsrealquick.Theonewe
careaboutisreturnOriginal.
ThereturnOriginalmethodisdefaultedtotrue,whichmeansthatit
returnstheoriginaldocument,nottheupdatedone,andwedon't
wantthat.Whenweupdateadocument,wewanttogetbackthat
updateddocument.Whatwe'regoingtodoissetreturnOriginalto
false,andthat'sgoingtohappeninourthirdandfinalargument.
Thisoneisalsogoingtobeanobject,returnOriginal,whichisgoingto
besettingequaltofalse.
Withthisinplace,wearedone.Wecantackonathencalltodo
somethingwiththeresults.I'llgetmyresultbackandIcansimply
printittothescreen,andwecantakealookatexactlywhatcomes
back: